<?php
namespace Back\Controller;
use Back\Common\BackController;

class RoleController extends BackController{
    public function showlist(){
        $info = D("Role") -> select();
        $this -> assign("info",$info);
        $this -> display();
    }

    public function distribute(){
        if(IS_POST){
            $role_id = I("post.role_id");
            $auth_id = I("post.auth_id");
            $m = D("Role");
            $data = $m -> dispose_role($auth_id);
            if($m -> where("role_id = $role_id") -> save($data)){
                $this -> success("分配权限成功",U("showlist"));
            }else{
                $this -> error("分配权限失败");
            }
        }else{
            $role_id = I("get.role_id");
            $m = M("role");
            $role_info = $m -> where("role_id = {$role_id}") -> find();
            $level0 = $m -> table("__AUTH__") -> where("auth_level = 0") -> select();
            $level1 = $m -> table("__AUTH__") -> where("auth_level = 1") -> select();

            $this -> assign("role_info",$role_info);
            $this -> assign("level0",$level0);
            $this -> assign("level1",$level1);
            $this -> display();
        }
    }
}